﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PushBox.Core
{
    public class Box : Position, IMovable
    {
        public bool Move(MoveType moveType)
        {
            Position p;
            switch (moveType)
            {
                case MoveType.Up:
                    // 箱子问地图：我的头上（x,y-1）有什么？
                    p = Map.GetObject(X, Y - 1);
                    //对象 is 类型: 判断某个对象是不是某种类型
                    if (p == null || p is Key)
                    {
                        this.Y--;
                        return true;
                    }
                    break;
                case MoveType.Down:
                    p = Map.GetObject(X, Y + 1);
                    if (p == null || p is Key)
                    {
                        this.Y++;
                        return true;
                    }
                    break;
                case MoveType.Left:
                    p = Map.GetObject(X - 1, Y);
                    if (p == null || p is Key)
                    {
                        this.X--;
                        return true;
                    }
                    break;
                case MoveType.Right:
                    p = Map.GetObject(X + 1, Y);
                    if (p == null || p is Key)
                    {
                        this.X++;
                        return true;
                    }
                    break;
            }
            return false;
        }
    }
}
